<template>
  <div class="portrait-aside tag-scrollbar">
    <el-collapse v-model="type" accordion @change="handleChange">
      <el-collapse-item v-for="item in list" :key="item.listTypeId" :name="item.listTypeId">
        <template slot="title">
          <icon-svg :name="item.listTypeId | typeIcon"></icon-svg>
          {{ item.listType }} （{{ item.listTagNum }}）
        </template>
        <div class="tag-wrap" v-loading="loading">
          <aside-all
            v-if="item.listTypeId === 1"
            @toggleLoading="toggleLoading"
            @drag="drag"
            @addItem="addItem"
            @clearConfig="$emit('clearConfig')"
          ></aside-all>
          <aside-calc
            v-else-if="item.listTypeId === 7"
            :ref="`aside-type-${item.listTypeId}`"
            @toggleLoading="toggleLoading"
            @drag="drag"
            @addItem="addItem"
          ></aside-calc>
          <aside-default
            v-else
            :ref="`aside-type-${item.listTypeId}`"
            :listType="item.listTypeId"
            :key="item.listTypeId"
            @toggleLoading="toggleLoading"
            @drag="drag"
            @addItem="addItem"
          ></aside-default>
        </div>
      </el-collapse-item>
    </el-collapse>
  </div>
</template>

<script>
import asideAll from './aside-all-item'
import asideCalc from './aside-calc-item'
import asideDefault from './aside-default-item'
export default {
  components: {
    asideAll,
    asideCalc,
    asideDefault
  },
  data() {
    return {
      loading: false,
      keyword: '',
      type: 1,
      list: []
    }
  },
  created() {
    this.getList()
  },
  methods: {
    handleChange(val) {
      if (val && val !== 1 && this.$refs[`aside-type-${val}`][0].getList) this.$refs[`aside-type-${val}`][0].getList()
    },
    getList() {
      this.loading = true
      this.$ajax({
        url: this.$ajax.setUrl('tagFactory/factoryListType'),
        method: 'get',
        params: this.$ajax.setParams()
      }).then(({ data }) => {
        if (data && data.code === '0') {
          this.list = []
          for (let i in data.data) {
            let item = Object.assign({}, data.data[i], { keyword: '', children: [] })
            this.list.push(item)
          }
          this.type = data.data[0].listTypeId
        } else {
          this.$message.error(data.data || data.msg)
        }
        this.loading = false
      })
    },
    toggleLoading(loading) {
      this.loading = loading
    },
    drag(event, item) {
      if (!item.assetId) return
      event.dataTransfer.setData('tagId', item.assetId)
    },
    addItem(item) {
      this.$emit('addItem', item)
    }
  },
  filters: {
    typeIcon(val) {
      let icon = ''
      switch (val) {
        case 1:
          // 全部
          icon = 'iconFactoryAll'
          break
        case 3:
          // 我的关注
          icon = 'iconFactoryWatch'
          break
        case 4:
          // 我的专辑
          icon = 'iconFactoryAlbum'
          break
        case 5:
          // 猜你喜欢
          icon = 'iconFactoryFav'
          break
        case 6:
          // 热门
          icon = 'iconFactoryHot'
          break
        case 7:
          // 计算型标签
          icon = 'iconCalculateTag'
          break
      }
      return icon
    }
  }
}
</script>

<style lang="scss">
.tag-portrait {
  .portrait-aside {
    width: 300px;
    height: 100%;
    border-right: 1px solid $border-color;
    overflow-y: auto;
    .el-collapse {
      height: 100%;
      color: #fff;
      background-color: #5973b2;
      .el-collapse-item__header {
        font-size: 15px;
        font-weight: bold;
        padding: 0 10px 0 20px;
        color: inherit;
        background-color: #6a86cc;
        border-color: #fff;
        svg {
          width: 25px;
          height: 25px;
          margin-right: 8px;
        }
      }
      .el-collapse-item__content {
        background-color: #f0f4f7;
        padding: 10px 0;
        line-height: 1;
      }
      .el-collapse-item__wrap {
        border: 0;
      }
    }
    .tag-wrap {
      color: #455fbc;
      .tab-title {
        font-size: 15px;
        padding: 5px 0 10px 45px;
        color: #455fbc;
        position: relative;
        svg {
          width: 18px;
          height: 18px;
          position: absolute;
          left: 20px;
          top: 2px;
          cursor: pointer;
        }
      }
      .el-input {
        padding: 0 20px;
        margin: 5px 0 10px 0;
        .el-input__inner {
          height: 35px;
          line-height: 35px;
          background-color: inherit;
          border-color: #455fbc;
        }
        .el-input__icon {
          line-height: 1 !important;
        }
        .el-input-group__append {
          padding: 0 15px;
          border-color: #455fbc;
          background-color: #455fbc;
          svg {
            width: 20px;
            height: 20px;
            color: #fff;
          }
        }
        .el-input__suffix {
          top: 6px;
          right: 25px;
          .el-input__suffix-inner {
            font-size: 18px;
            color: #4d82e9;
          }
        }
      }
      .drag-item {
        padding: 0 30px 0 20px;
        line-height: 40px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        cursor: pointer;
        position: relative;
        &:hover {
          background-color: #c0d2f6;
          &:not(.tag-disabled):before {
            width: 10px;
            height: 10px;
            content: '';
            border: 2px solid rgba(#000, 0.3);
            background-color: #a8fff9;
            border-radius: 50%;
            position: absolute;
            top: 15px;
            left: 5px;
          }
          &.tag-disabled .icon-disabled {
            display: block;
          }
        }
        .el-icon-arrow-right {
          position: absolute;
          top: 15px;
          right: 15px;
        }
        .asset-name {
          width: 100%;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
        }
        &.tag-item {
          padding-right: 60px;
          .list-handler {
            position: absolute;
            top: 0;
            right: 10px;
            .plus {
              display: inline-block;
              width: 18px;
              height: 18px;
              margin-top: -5px;
              border: 1px solid #5f8eec;
              color: #5f8eec;
              line-height: 15px;
              text-align: center;
              border-radius: 50%;
              vertical-align: middle;
              i {
                font-size: 12px;
              }
            }
            svg {
              width: 16px;
              height: 16px;
              color: #455fbc;
              margin: -5px 5px 0 10px;
              vertical-align: middle;
            }
          }
        }
        &.tag-disabled {
          cursor: default;
          .asset-name {
            opacity: 0.45;
          }
          .icon-disabled {
            width: 10px;
            height: 10px;
            color: #ff0000;
            margin-top: -5px;
            position: absolute;
            top: 50%;
            left: 5px;
            display: none;
          }
        }
      }
      p {
        padding: 0 20px;
        margin: 10px 0 20px 0;
      }
      .el-pagination {
        padding: 2px 20px;
        white-space: normal;
        &.is-background .el-pager li:not(.disabled).active {
          background-color: #455fbc;
        }
      }
    }
  }
}
</style>
